﻿#ifndef FRMMAIN_H
#define FRMMAIN_H

#include <QAudioDevice>
#include <QCamera>
#include <QCameraDevice>
#include <QDialog>
#include <QImageCapture>
#include <QMediaCaptureSession>
#include <QMediaDevices>
#include <QMediaRecorder>
#include <QTreeWidgetItem>

namespace Ui {
class frmMain;
}

class frmMain : public QDialog {
    Q_OBJECT

public:
    explicit frmMain(QWidget *parent = 0);
    ~frmMain();

protected:
    bool eventFilter(QObject *watched, QEvent *event);

private:
    Ui::frmMain *ui;

    QMediaCaptureSession captureSession;

    QScopedPointer<QMediaRecorder> mediaRecorder;
    QScopedPointer<QImageCapture> imgCapture;

    QScopedPointer<QAudioInput> audioInput;
    QScopedPointer<QCamera> curCamera;

    QList<QCameraFormat> cameraFormats;
    bool recording;

    void loadDevices();
    void loadCameraProperties(const QCameraDevice &camera);
    void setCamera(const QCameraDevice &cameraDevice);
    void setCameraSelectedFormat();

    void startCamera();
    void stopCamera();


private:
    //边距+可移动+可拉伸
    int padding;
    bool moveEnable;
    bool resizeEnable;

    //无边框窗体
    QWidget *widget;

    //鼠标是否按下+按下坐标+按下时窗体区域
    bool mousePressed;
    QPoint mousePoint;
    QRect mouseRect;

    //鼠标是否按下某个区域+按下区域的大小
    //依次为 左侧+右侧+上侧+下侧+左上侧+右上侧+左下侧+右下侧
    QList<bool> pressedArea;
    QList<QRect> pressedRect;

    void initResizeMembers();

private slots:
    void initForm();
    void buttonClick();

private slots:
    void on_btnMenu_Min_clicked();
    void on_btnMenu_Max_clicked();
    void on_btnMenu_Close_clicked();

    void on_toolButtonApply_clicked();
    void on_toolButtonCapture_clicked();
    void on_toolButtonRecord_clicked();

    void on_treeWidgetCamera_itemDoubleClicked(QTreeWidgetItem *item,
                                               int column);
    void on_comboBoxPixFormat_currentIndexChanged(int index);
    void on_comboBoxResolution_currentIndexChanged(int index);
};

#endif // UIDEMO01_H
